﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fang.Common
{
    public class Decimal_TextBox : System.Windows.Forms.TextBox
    {
        protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
            { e.Handled = true; }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                if (e.KeyChar != '.' || this.Text.Trim().Length == 0)//小数点   
                { e.Handled = true; }
                if (this.Text.Trim().LastIndexOf('.') != -1)
                { e.Handled = true; }
            }
        }
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }
    }
}
